home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / tone.c < prev    next >
Text File  |  1985-06-03  |  1KB  |  32 lines

  1. /* Program: tone.c */
  2. /* #include <tone.c> */
  3. /* Usage: tone(freq,time); */
  4.  
  5. #define TIMERMODE 182        /* Code to put timer in right mode */
  6. #define FREQSCALE 1190000L    /* basic time frequency in Hz */
  7. #define TIMESCALE 1230L        /* number of counts in .1 second */
  8. #define T_MODEPORT 67        /* port controls timer mode */
  9. #define FREQPORT 66            /* port controls tone frequency */
  10. #define BEEPPORT 97            /* port controls speaker */
  11. #define ON 79                /* signal to turn speaker on */
  12.  
  13. tone(freq,time)
  14. int freq, time;
  15. {
  16.     int hibyt, lobyt, port;
  17.     long i, count, divisor;
  18.  
  19.     divisor=FREQSCALE/freq;        /* scale frequency to timer units */
  20.     lobyt=divisor % 256;        /* break integer into */
  21.     hibyt=divisor / 256;        /* two bytes */
  22.     count=TIMESCALE*time;        /* convert time to TIMER unites */
  23.     outp(T_MODEPORT,TIMERMODE);    /* prepare timer for input */
  24.     outp(FREQPORT,lobyt);        /* set low byte of timer register */
  25.     outp(FREQPORT,hibyt);        /* set high byte of timer register */
  26.     port=inp(BEEPPORT);        /* save port setting */
  27.     outp(BEEPPORT,ON);        /* turn speaker on */
  28.     for(i=0; i<count; i++)
  29.     ;
  30.     outp(BEEPPORT,port);        /* turn speaker off, restore setting */
  31. }
  32.